# Makefile.x86: Makefile for Linux PC
# You can build specific .ko name by assiging the "MTK_COMBO_CHIP" and "hif" parameters
# hif = pcie or sdio or usb
# Examples:
# - Default=wlan_mt6632_pcie.ko:
# 	make -f Makefile.x86
# - wlan_mt7663_usb.ko:
# 	make -f Makefile.x86 MTK_COMBO_CHIP=MT7663 hif=usb
# Note: Chip ID must be uppercase. E.g., MT7663

LINUX_SRC=/lib/modules/$(shell uname -r)/build

export CONFIG_MTK_COMBO_PLATFORM=x86
export MTK_COMBO_CHIP=MT6632

PWD=$(shell pwd)
DRIVER_DIR=$(PWD)

export CONFIG_MTK_WIFI_ONLY=m
export CONFIG_MTK_COMBO=m
export CONFIG_MTK_COMBO_WIFI=m
export CONFIG_MTK_COMBO_COMM=m
export CONFIG_MTK_COMBO_COMM_UART=m
export CONFIG_MTK_COMBO_COMM_SDIO=m
export CONFIG_MT_WIFI_CHRDEV=m
ifneq (,$(wildcard ../../wlan_service/))
export MTK_WLAN_SERVICE_PATH=../../wlan_service/
endif
ifneq ($(BACKPORTED_KERNEL_VERSION),)
export CFG_CFG80211_VERSION ?= $(BACKPORTED_KERNEL_VERSION)
endif

# pcie | sdio | usb | ut
ifeq ($(hif),)
    hif=pcie
endif

MODULES_NAME := wlan_$(shell echo $(word 1, $(MTK_COMBO_CHIP)) | tr A-Z a-z)

export CONFIG_MTK_COMBO_WIFI_HIF=$(hif)

export CONFIG_MTK_COMBO_PLAT_PATH=x86

#need to support these 3 CONFIG_ in Android.mk::Begin
export CONFIG_MTK_WIFI_POWER_ON_DOWNLOAD_EMI_ROM_PATCH=$(wifi_pwron_emi_patch_dl)

export CONFIG_MTK_WIFI_DOWNLOAD_DYN_MEMORY_MAP=$(wifi_dl_dyn_mem_map)

export CONFIG_MTK_WIFI_ROM_PATCH_NO_SEM_CTRL=$(wifi_rom_patch_no_sem_ctrl)
#need to support these 3 CONFIG_ in Android.mk::End

##############################################################
# Compile options
##############################################################
#/***** Common part ******/

# Define maximum different channels supported for ieee80211_iface_combination setting.
#CFG_NUM_DIFFERENT_CHANNELS_STA=1
#CFG_NUM_DIFFERENT_CHANNELS_P2P=1

# Define initial driver running mode.
# 0=RUNNING_P2P_MODE, 1=RUNNING_AP_MODE, 2=RUNNING_DUAL_AP_MODE, 3=RUNNING_P2P_AP_MODE
#CFG_DRIVER_INITIAL_RUNNING_MODE=3

# Define to enable Android wake_lock
#CFG_ENABLE_WAKE_LOCK=0

# For wpa_supplicant w/o MTK priv lib
# y: enable, n: disable
CFG_ANDROID_AOSP_PRIV_CMD=n

#CFG_DEFAULT_DBG_LEVEL=0xF

CFG_TX_DIRECT_USB=1

CFG_RX_DIRECT_USB=1

CFG_USB_REQ_TX_DATA_FFA_CNT=10

CFG_USB_REQ_TX_DATA_CNT=2

CFG_USB_REQ_RX_DATA_CNT=2

CFG_SYS_DVT_SUPPORT=0

CFG_SYS_DVT_DMASCHDL_SUPPORT=0

#CFG_SUPPORT_DFS_MASTER=1

#CFG_SUPPORT_SINGLE_SKU_LOCAL_DB=0

# Report all bss networks to cfg80211 when do p2p scan
CFG_P2P_SCAN_REPORT_ALL_BSS=0

# Support to change sta, p2p, ap interface names
# y: enable, n: disable
# eg. insmod wlan_mt76x8_usb.ko sta=wlan p2p=p2p ap=ap
CFG_DRIVER_INF_NAME_CHANGE=n

# Support firmware auto roaming
#CFG_SUPPORT_ROAMING=0

ifeq ($(CFG_ANDROID_AOSP_PRIV_CMD), y)
PLATFORM_FLAGS += -DCFG_ANDROID_AOSP_PRIV_CMD
endif

# 1: Enable SDIO RX Tasklet De-Aggregation
# 0: Disable (default)
CFG_SDIO_RX_AGG_TASKLET=0

# CFG_WIFI_WORKAROUND_HWITS00012836_WTBL_SEARCH_FAIL
ifeq ($(MTK_COMBO_CHIP), soc3_0)
CFG_WIFI_WORKAROUND_HWITS00012836_WTBL_SEARCH_FAIL=1
endif

#/***** Manage configs into compile options ******/
ifneq ($(CFG_DFS_CHSW_FORCE_BW20),)
PLATFORM_FLAGS += -DCFG_DFS_CHSW_FORCE_BW20=$(CFG_DFS_CHSW_FORCE_BW20)
endif

ifneq ($(CFG_NUM_DIFFERENT_CHANNELS_STA),)
PLATFORM_FLAGS += -DCFG_NUM_DIFFERENT_CHANNELS_STA=$(CFG_NUM_DIFFERENT_CHANNELS_STA)
endif

ifneq ($(CFG_NUM_DIFFERENT_CHANNELS_P2P),)
PLATFORM_FLAGS += -DCFG_NUM_DIFFERENT_CHANNELS_P2P=$(CFG_NUM_DIFFERENT_CHANNELS_P2P)
endif

ifneq ($(CFG_DRIVER_INITIAL_RUNNING_MODE),)
PLATFORM_FLAGS += -DCFG_DRIVER_INITIAL_RUNNING_MODE=$(CFG_DRIVER_INITIAL_RUNNING_MODE)
endif

ifneq ($(CFG_ENABLE_WAKE_LOCK),)
PLATFORM_FLAGS += -DCFG_ENABLE_WAKE_LOCK=$(CFG_ENABLE_WAKE_LOCK)
endif

ifneq ($(CFG_DEFAULT_DBG_LEVEL),)
PLATFORM_FLAGS += -DCFG_DEFAULT_DBG_LEVEL=$(CFG_DEFAULT_DBG_LEVEL)
endif

ifneq ($(CFG_TX_DIRECT_USB),)
PLATFORM_FLAGS += -DCFG_TX_DIRECT_USB=$(CFG_TX_DIRECT_USB)
endif

ifneq ($(CFG_RX_DIRECT_USB),)
PLATFORM_FLAGS += -DCFG_RX_DIRECT_USB=$(CFG_RX_DIRECT_USB)
endif

ifneq ($(CFG_USB_REQ_TX_DATA_FFA_CNT),)
PLATFORM_FLAGS += -DCFG_USB_REQ_TX_DATA_FFA_CNT=$(CFG_USB_REQ_TX_DATA_FFA_CNT)
endif

ifneq ($(CFG_USB_REQ_TX_DATA_CNT),)
PLATFORM_FLAGS += -DCFG_USB_REQ_TX_DATA_CNT=$(CFG_USB_REQ_TX_DATA_CNT)
endif

ifneq ($(CFG_USB_REQ_RX_DATA_CNT),)
PLATFORM_FLAGS += -DCFG_USB_REQ_RX_DATA_CNT=$(CFG_USB_REQ_RX_DATA_CNT)
endif

ifneq ($(CFG_SUPPORT_ROAMING),)
PLATFORM_FLAGS += -DCFG_SUPPORT_ROAMING=$(CFG_SUPPORT_ROAMING)
endif

ifneq ($(CFG_SUPPORT_DFS_MASTER),)
PLATFORM_FLAGS += -DCFG_SUPPORT_DFS_MASTER=$(CFG_SUPPORT_DFS_MASTER)
endif

ifneq ($(CFG_SUPPORT_SINGLE_SKU_LOCAL_DB),)
PLATFORM_FLAGS += -DCFG_SUPPORT_SINGLE_SKU_LOCAL_DB=$(CFG_SUPPORT_SINGLE_SKU_LOCAL_DB)
endif

ifeq ($(CFG_DRIVER_INF_NAME_CHANGE), y)
PLATFORM_FLAGS += -DCFG_DRIVER_INF_NAME_CHANGE
endif

ifneq ($(CFG_SYS_DVT_SUPPORT),)
ifeq ($(CFG_SYS_DVT_SUPPORT), 0)
# Check dependency
CFG_SYS_DVT_DMASCHDL_SUPPORT=0
endif
PLATFORM_FLAGS += -DCFG_SUPPORT_WIFI_SYSDVT=$(CFG_SYS_DVT_SUPPORT)
export CFG_SUPPORT_WIFI_SYSDVT=$(CFG_SYS_DVT_SUPPORT)
ifneq ($(CFG_SYS_DVT_DMASCHDL_SUPPORT),)
PLATFORM_FLAGS += -DCFG_SUPPORT_DMASHDL_SYSDVT=$(CFG_SYS_DVT_DMASCHDL_SUPPORT)
export CFG_SUPPORT_DMASHDL_SYSDVT=$(CFG_SYS_DVT_DMASCHDL_SUPPORT)
endif
endif

ifneq ($(CFG_P2P_SCAN_REPORT_ALL_BSS),)
PLATFORM_FLAGS += -DCFG_P2P_SCAN_REPORT_ALL_BSS=$(CFG_P2P_SCAN_REPORT_ALL_BSS)
endif

ifneq ($(CFG_SDIO_RX_AGG_TASKLET),)
PLATFORM_FLAGS += -DCFG_SDIO_RX_AGG_TASKLET=$(CFG_SDIO_RX_AGG_TASKLET)
endif

# CFG_WIFI_WORKAROUND_HWITS00012836_WTBL_SEARCH_FAIL
ifeq ($(MTK_COMBO_CHIP), soc3_0)
PLATFORM_FLAGS += -DCFG_WIFI_WORKAROUND_HWITS00012836_WTBL_SEARCH_FAIL=$(CFG_WIFI_WORKAROUND_HWITS00012836_WTBL_SEARCH_FAIL)
endif

ifeq ($(CONFIG_MTK_COMBO_PLATFORM), x86)
PLATFORM_FLAGS += -DCFG_BUILD_X86_PLATFORM
endif

all: driver

driver:
	+cd $(DRIVER_DIR) && make -C $(LINUX_SRC) M=$(DRIVER_DIR) PLATFORM_FLAGS="$(PLATFORM_FLAGS)" modules
	@cd $(DRIVER_DIR) && cp $(MODULES_NAME)_$(hif).ko $(MODULES_NAME).ko

clean: driver_clean

driver_clean:
	cd $(DRIVER_DIR) && make -C $(LINUX_SRC) M=$(DRIVER_DIR) clean

.PHONY: all clean driver driver_clean
